package com.config.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.config.common.Result;
import com.config.entity.Prompt;
import com.config.service.PromptService;
import com.config.vo.PromptVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  异常提示前端控制器
 * </p>
 *
 * @author Lu
 * @since 2021-02-04
 */
@Api (tags ="异常提示设置页面接口")
@RestController
@RequestMapping("/config/prompt")
public class PromptController {

	@Autowired
	PromptService promptService;

	@ApiOperation ("获取所有信息（分页）")
	@GetMapping ("/promptPageAll")
	public Result selectPageAll(Integer current, Integer size) {
		PromptVo userVo = new PromptVo();
		IPage<Prompt> page = new Page<>(current, size);
		IPage<Prompt> page1 = promptService.page(page, null);
		userVo.setCurrent(current);
		userVo.setSize(size);
		userVo.setTotal(page.getTotal());
		userVo.setPromptList(page.getRecords());
		return Result.succ(page1);
	}

	@ApiOperation ("修改列表数据")
	@PutMapping ("/prupd")
	public Result upprChoose(@RequestBody Prompt prompt) {
		boolean update = promptService.updateById(prompt);
		if (update) {
			return Result.succ(prompt);
		} else {
			return Result.fail("修改失败");
		}
	}
}

